package client

import (
	"github.com/gin-gonic/gin"
	"likeadmin/admin/schemas/req"
	"likeadmin/admin/service/client"
	"likeadmin/config"
	"likeadmin/core"
	"likeadmin/core/request"
	"likeadmin/core/response"
	"likeadmin/middleware"
	"likeadmin/util"
)

var RechargeGearTypeGroup = core.Group("/client", newTypeHandler, regType, middleware.TokenAuth())

func newTypeHandler(srv client.IRechargeGearTypeService) *rechargeGearType {
	return &rechargeGearType{srv: srv}
}

func regType(rg *gin.RouterGroup, group *core.GroupBase) error {
	return group.Reg(func(handle *rechargeGearType) {
		rg.GET("/recharge_gear_type/all", handle.all)
		rg.GET("/recharge_gear_type/list", handle.list)
		rg.GET("/recharge_gear_type/detail", handle.detail)
		rg.POST("/recharge_gear_type/add", handle.add)
		rg.POST("/recharge_gear_type/edit", handle.edit)
	})
}

type rechargeGearType struct {
	srv client.IRechargeGearTypeService
}

// all 角色所有
func (rh rechargeGearType) all(c *gin.Context) {
	adminId := config.AdminConfig.GetAdminId(c)
	res, err := rh.srv.All(adminId)
	response.CheckAndRespWithData(c, res, err)
}

// list type列表
func (hd rechargeGearType) list(c *gin.Context) {
	var page request.PageReq
	var listReq req.RechargeGearTypeListReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
		return
	}
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
		return
	}
	res, err := hd.srv.List(page, listReq)
	response.CheckAndRespWithData(c, res, err)
}

// detail type详情
func (hd rechargeGearType) detail(c *gin.Context) {
	var detailReq req.RechargeGearTypeDetailReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
		return
	}
	res, err := hd.srv.Detail(detailReq.TId)
	response.CheckAndRespWithData(c, res, err)
}

// add type新增
func (hd rechargeGearType) add(c *gin.Context) {
	var addReq req.RechargeGearTypeAddReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &addReq)) {
		return
	}
	response.CheckAndResp(c, hd.srv.Add(addReq))
}

// edit type编辑
func (hd rechargeGearType) edit(c *gin.Context) {
	var editReq req.RechargeGearTypeEditReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &editReq)) {
		return
	}
	response.CheckAndResp(c, hd.srv.Edit(editReq))
}
